<template>
	<el-config-provider :size="getGlobalComponentSize" :locale="getGlobalI18n">
		<router-view v-show="themeConfig.lockScreenTime > 1" />
		<LockScreen v-if="themeConfig.isLockScreen" />
		<Setings ref="setingsRef" v-show="themeConfig.lockScreenTime > 1" />
		<CloseFull v-if="!themeConfig.isLockScreen" />
	</el-config-provider>
</template>

<script setup lang="ts" name="app">
import { defineAsyncComponent, computed, ref, onBeforeMount, onMounted, onUnmounted, nextTick, watch } from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { storeToRefs } from 'pinia';
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
import { useThemeConfig } from '/@/stores/themeConfig';
import other from '/@/utils/other';
import { Local, Session } from '/@/utils/storage';
import mittBus from '/@/utils/mitt';
import setIntroduction from '/@/utils/setIconfont';
import quanCity from '/@/utils/cityList_all.json';

sessionStorage.quanCity = JSON.stringify(quanCity);

// 引入组件
const LockScreen = defineAsyncComponent(() => import('/@/layout/lockScreen/index.vue'));
const Setings = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/setings.vue'));
const CloseFull = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/closeFull.vue'));

// 定义变量内容
const { messages, locale } = useI18n();
const setingsRef = ref();
const route = useRoute();
const stores = useTagsViewRoutes();
const storesThemeConfig = useThemeConfig();
const { themeConfig } = storeToRefs(storesThemeConfig);

// 获取全局组件大小
const getGlobalComponentSize = computed(() => {
	return other.globalComponentSize();
});
// 获取全局 i18n
const getGlobalI18n = computed(() => {
	return messages.value[locale.value];
});
// 设置初始化，防止刷新时恢复默认
onBeforeMount(() => {
	// 设置批量第三方 icon 图标
	setIntroduction.cssCdn();
	// 设置批量第三方 js
	setIntroduction.jsCdn();
});
// 页面加载时
onMounted(() => {
	nextTick(() => {
		// 监听布局配'置弹窗点击打开
		mittBus.on('openSetingsDrawer', () => {
			setingsRef.value.openDrawer();
		});
		// 获取缓存中的布局配置
		if (Local.get('themeConfig')) {
			storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') });
			document.documentElement.style.cssText = Local.get('themeConfigStyle');
		}
		// 获取缓存中的全屏配置
		if (Session.get('isTagsViewCurrenFull')) {
			stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'));
		}
	});
});
// 页面销毁时，关闭监听布局配置/i18n监听
onUnmounted(() => {
	mittBus.off('openSetingsDrawer', () => {});
});
// 监听路由的变化，设置网站标题
watch(
	() => route.path,
	() => {
		other.useTitle();
	},
	{
		deep: true,
	}
);
</script>
<style lang="scss">
.flex {
	display: flex;
}
.flex_center {
	display: flex;
	justify-content: center;
}
.flex_ac {
	display: flex;
	align-items: center;
}
.flex_sb {
	display: flex;
	justify-content: space-between;
}
.flex_row {
	display: flex;
	flex-direction: row;
}
.flex_col {
	display: flex;
	flex-direction: column;
}
.flex_w {
	display: flex;
	flex-wrap: wrap;
}

.text_line2 {
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 2; /* 定义文本的行数 */
	overflow: hidden;
	text-overflow: ellipsis;
}
.text_line {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

@for $i from 1 through 200 {
	.w#{$i} {
		width: 1% * $i;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}
	.h#{$i} {
		height: 1px * $i;
	}
	.mt#{$i} {
		margin-top: 1px * $i !important;
	}
	.mb#{$i} {
		margin-bottom: 1px * $i !important;
	}
	.ml#{$i} {
		margin-left: 1px * $i !important;
	}
	.mr#{$i} {
		margin-right: 1px * $i !important;
	}
	.pt#{$i} {
		padding-top: 1px * $i !important;
	}
	.pb#{$i} {
		padding-bottom: 1px * $i !important;
	}
	.pl#{$i} {
		padding-left: 1px * $i !important;
	}
	.pr#{$i} {
		padding-right: 1px * $i !important;
	}
}

.list_div {
	overflow-y: auto;
	&::-webkit-scrollbar {
		width: 0;
		width: 6px;
		// background-color: rgba(255, 255, 255, 0.5);
		border-radius: 4px;
	}
	&::-webkit-scrollbar-thumb {
		width: 0;
		border-radius: 10px;
		// background-color: #282932;
		border: 1px solid transparent;
		background-clip: padding-box;
	}
}
.el-row {
	height: 100%;
}
.el-col {
	height: 100%;
}
.el-card {
	height: 100%;
}
.el-card__body {
	height: calc(100% - 65px);
}
</style>
